﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ricciolo.StylesExplorer.Model;
using System.ComponentModel;
using System.Xml.XPath;
using Ricciolo.StylesExplorer.Components;

namespace Ricciolo.StylesExplorer.Controls
{
    class XamlFileTreeNode : ExplorerTreeNode, ITreeNodeChildren, IFullXPathNavigable
    {

        private IXamlFile xamlFile;

        public XamlFileTreeNode(IXamlFile xamlFile)
        {
            this.xamlFile = xamlFile;
            string u = xamlFile.Name;
            string prefix = @"component%5C";
            this.Text = u.Substring(u.IndexOf(prefix) + prefix.Length);
            this.ImageKey = "Resources";
            this.SelectedImageKey = this.ImageKey;
        }

        public IXamlFile XamlFile
        {
            get { return xamlFile; }
        }

        #region ITreeNodeChildren Members

        System.ComponentModel.IBindingList ITreeNodeChildren.Children
        {
            get { return xamlFile.Resources as IBindingList; }
        }

        #endregion

        #region IFullXPathNavigable Members

        XPathNavigator IFullXPathNavigable.CreateNavigator(bool includeDependencies)
        {
            if (xamlFile is IXPathNavigable)
                return ((IXPathNavigable)xamlFile).CreateNavigator();

            return null;
        }

        #endregion
    }
}
